package com.my.commonlibrary.fragment;

import com.my.commonlibrary.adapter.PullToRefreshAdapter;
import com.my.commonlibrary.base.BasePullToRefreshFragment;
import com.my.commonlibrary.base.HolderAdapter;
import com.my.commonlibrary.model.PullToRefreshEntity;
import com.my.pulltorefresh.library.PullToRefreshBase;

import java.util.ArrayList;
import java.util.List;

/**
 * Author : Cooper
 * Time : 2016/9/27  15:35
 * Description : 具体下拉上拉刷新实现类
 */

public class H_PullToRefreshFragment extends BasePullToRefreshFragment {

    private List<PullToRefreshEntity> pullToRefreshEntityList = new ArrayList<>();
    private PullToRefreshAdapter pullToRefreshAdapter;
    private int count;

    @Override
    protected HolderAdapter getAdapter() {
        pullToRefreshEntityList.add(new PullToRefreshEntity("这是内容啊"));
        pullToRefreshEntityList.add(new PullToRefreshEntity("水电费水电费"));
        pullToRefreshEntityList.add(new PullToRefreshEntity("这是内容工会经费感觉很啊"));
        pullToRefreshEntityList.add(new PullToRefreshEntity("一套统一"));
        pullToRefreshEntityList.add(new PullToRefreshEntity("帮你们，好快"));
        pullToRefreshEntityList.add(new PullToRefreshEntity("以偶爻好快"));
        pullToRefreshEntityList.add(new PullToRefreshEntity("请问而儿童"));
        pullToRefreshAdapter = new PullToRefreshAdapter(getActivity(),pullToRefreshEntityList);
        return pullToRefreshAdapter;
    }

    @Override
    public void onPullDownToRefresh(PullToRefreshBase refreshView) {
        mListView.postDelayed(new Runnable() {
            @Override
            public void run() {
                count++;
                pullToRefreshEntityList.add(0,new PullToRefreshEntity("这是新添加的数据 == "+count));
                pullToRefreshAdapter.notifyDataSetChanged();
                refreshComplete();
            }
        },2000);
    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase refreshView) {
        mListView.postDelayed(new Runnable() {
            @Override
            public void run() {
                count++;
                pullToRefreshEntityList.add(new PullToRefreshEntity("这是新添加的数据 == "+count));
                pullToRefreshAdapter.notifyDataSetChanged();
                refreshComplete();
            }
        },2000);
    }
}
